package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;
    /**
     * 添加好友
     * */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        String s = map.get("userId").toString();
        Long userId = Long.valueOf(s);
        messagesService.contacts(userId);

        return ResponseEntity.ok(null);
    }

    /**
     * 查询好友列表
     * */
    @GetMapping("/contacts")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1")Integer page,
                                   @RequestParam(defaultValue = "10")Integer pagesize){

        PageResult vo = messagesService.findFriends(page,pagesize);
        return ResponseEntity.ok(vo);
    }
}
